package com.pomr.controller.common;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pomr.model.data.EquipmentMessage;
import com.pomr.model.data.MonitorMessage;
import com.pomr.service.common.EquipmentMessageService;
import com.pomr.util.common.ResponseData;

/**
 * 
 * 类名称： EquipmentMessageController
 * 创建人： Administrator
 * 创建时间：2018年5月23日 下午2:42:30
 * 类描述：设备信息对外接口
 */
@Controller
@RequestMapping("/equipMessage")
public class EquipmentMessageController {
	@Autowired
	@Qualifier("equipmentMessageServiceImpl")
	private EquipmentMessageService equipmentMessageService;
	
	/**
	 * 根据设备sn，获取设备信息，如设备的型号，厂家，SIM信息等
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value="/equipMessage",method=RequestMethod.GET)
	public ResponseData searchEquipmentMessage(String sn) throws Exception{
		ResponseData pd = null;
		if(sn == null || sn.equals("")){
			pd = ResponseData.custom("sn编号不能为空");
		}else{
			EquipmentMessage em = equipmentMessageService.searchEquipBySn(sn);
			pd = ResponseData.ok();
			if(em != null){
				pd.putDataValue("equipmentMessage", em);
			}
		}
		return pd;
	}
	
	/**
	 * 获取指定设备sn的检测结果 
	 * @param sn 
	 * @param startTime 开始时间      格式：yyyy-MM-dd 不设置时间默认查询最近一个月
	 * @param endTime	截止时间      格式：yyyy-MM-dd
	 * @param idcard	身份证号
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value="/monitorMessage",method=RequestMethod.GET)
	public ResponseData searchMonitoringData(String sn, String startTime, String endTime, String idcard) throws Exception{
		ResponseData pd = null;
		if(sn == null || sn.equals("")){
			pd = ResponseData.custom("sn编号不能为空");
		}else{
			List<MonitorMessage> datas = equipmentMessageService.searchMonitorBySn(sn, startTime, endTime, idcard);
			pd = ResponseData.ok();
			if(datas != null){
				pd.putDataValue("monitoringData", datas);
			}
		}
		return pd;
	}
	
	/**
	 * 根据身份证号，获取该身份证号的所有设备
	 * @param idcard
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value="/fromidcard",method=RequestMethod.GET)
	public ResponseData searchEquipmentByIdcard(String idcard) throws Exception{
		ResponseData pd = null;
		if(idcard == null || idcard.equals("")){
			pd = ResponseData.custom("身份证号不能为空");
		}else{
			List<EquipmentMessage> ems = equipmentMessageService.searchEquipByIdcard(idcard);
			pd = ResponseData.ok();
			if(ems != null){
				pd.putDataValue("equipmentMessages", ems);
			}
		}
		return pd;
	}

}
